package com.ruoyi.web.controller.animal;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.animal.domain.AnimalInfoUser;
import com.ruoyi.animal.service.IAnimalInfoUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 动物与户主联Controller
 *
 * @author zhezhi
 * @date 2022-10-06
 */
@RestController
@RequestMapping("/commerce/animalUser")
public class AnimalInfoUserController extends BaseController
{
    @Autowired
    private IAnimalInfoUserService animalInfoUserService;

    /**
     * 查询动物与户主联列表
     */
    @PreAuthorize("@ss.hasPermi('commerce:animalUser:list')")
    @GetMapping("/list")
    @ApiOperation("查询动物与户主联列表")
    public TableDataInfo list(AnimalInfoUser animalInfoUser)
    {
        startPage();
        List<AnimalInfoUser> list = animalInfoUserService.selectAnimalInfoUserList(animalInfoUser);
        return getDataTable(list);
    }

    /**
     * 导出动物与户主联列表
     */
    @PreAuthorize("@ss.hasPermi('commerce:animalUser:export')")
    @Log(title = "动物与户主联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出动物与户主联列表")
    public void export(HttpServletResponse response, AnimalInfoUser animalInfoUser)
    {
        List<AnimalInfoUser> list = animalInfoUserService.selectAnimalInfoUserList(animalInfoUser);
        ExcelUtil<AnimalInfoUser> util = new ExcelUtil<AnimalInfoUser>(AnimalInfoUser.class);
        util.exportExcel(response, list, "动物与户主联数据");
    }

    /**
     * 获取动物与户主联详细信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:animalUser:query')")
    @GetMapping(value = "/{infoId}")
    @ApiOperation("获取动物与户主联列表")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return AjaxResult.success(animalInfoUserService.selectAnimalInfoUserByInfoId(infoId));
    }

    /**
     * 新增动物与户主联
     */
    @PreAuthorize("@ss.hasPermi('commerce:animalUser:add')")
    @Log(title = "动物与户主联", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增动物与户主联")
    public AjaxResult add(@RequestBody AnimalInfoUser animalInfoUser)
    {
        return toAjax(animalInfoUserService.insertAnimalInfoUser(animalInfoUser));
    }

    /**
     * 修改动物与户主联
     */
    @PreAuthorize("@ss.hasPermi('commerce:animalUser:edit')")
    @Log(title = "动物与户主联", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改动物与户主联")
    public AjaxResult edit(@RequestBody AnimalInfoUser animalInfoUser)
    {
        return toAjax(animalInfoUserService.updateAnimalInfoUser(animalInfoUser));
    }

    /**
     * 删除动物与户主联
     */
    @PreAuthorize("@ss.hasPermi('commerce:animalUser:remove')")
    @Log(title = "动物与户主联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoIds}")
    @ApiOperation("删除动物与户主联")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(animalInfoUserService.deleteAnimalInfoUserByInfoIds(infoIds));
    }
}
